﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NS.Utilities;
using NS.BLL.Systems;
using Model;
using BLL;

public partial class Platform_CouponsModify : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DataShow();
        }
    }
    private void DataShow()
    {
        CouponsScheme Model = CouponsSchemeService.GetCouponsSchemeBySchemeID(int.Parse(Request.QueryString["SchemeID"].ToString()));
        if (Model != null)
        {
            txtCouponName.Text = Model.CouponName;
            txtQuantity.Text = Model.Quantity.ToString();
            txtValidDays.Text = Model.ValidDays.ToString();
            txtOldPirce.Text = Model.OldPrice.ToString();
            txtPrePirce.Text = Model.PrePrice.ToString();
            txtScope.Text = Model.Scope;
            txtExplain.Text = Model.Explain;
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        CouponsScheme Model = CouponsSchemeService.GetCouponsSchemeBySchemeID(int.Parse(Request.QueryString["SchemeID"].ToString()));
        Model.CouponName = txtCouponName.Text;
        Model.Quantity = Convert.ToInt32(txtQuantity.Text);
        Model.ValidDays = Convert.ToInt32(txtValidDays.Text);
        Model.OldPrice = Convert.ToDecimal(txtOldPirce.Text);
        Model.PrePrice = Convert.ToDecimal(txtPrePirce.Text);
        Model.Scope = txtScope.Text;
        Model.Explain = txtExplain.Text;
        if (CouponsSchemeService.UpdateCouponsSchemeBySchemeID(Model) > 0)
        {
            MessageBox.AppendScript(this, "$(':input[id$=\"btnBindData\"]', window.parent.document.body).click();");
        }
        else
        {
            MessageBox.ShowSaveError(this);
        }

    }
}